﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LispInterpretor.DataTypes;
using LispInterpretor;

namespace UnitTests
{
    [TestClass]
    public class TestLet
    {
        [TestMethod]
        public void TestBasicLetExpression()
        {
            Assert.AreEqual(Number.Parse("12"), Evaluator.Eval("(let ((a 3) (b 4)) (* a b))"));
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidProgramException))]
        public void TestInvalidBindingList()
        {
            Evaluator.Eval("(let ((a 3 4)) a)");
        }

        /// <summary>
        /// This test should fail because the evaluation of the 
        /// first binding "a" should not be visible to the second binding "b"
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(InvalidProgramException))]
        public void TestParallelBinding()
        {
            Evaluator.Eval("(let ((a 3) (b a)) b)");
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidProgramException))]
        public void TestMultipleBindingsForTheSameLabel()
        {
            Evaluator.Eval("(let ((a 3) (a 4)) a)");
        }
    }
}
